package com.example.mybaties.testone.aop.advice;


import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 环绕增强，相当于前置和后置的综合体
 */
public class GreetingIntercepter implements MethodInterceptor {

    private Logger logger = LogManager.getLogger(this.getClass());

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        Object[] args = methodInvocation.getArguments();//获取参数
        String str = (String) args[0];
        logger.debug("GreetingIntercepter.............方法前......" + str);

        Object result = methodInvocation.proceed();

        logger.debug("GreetingIntercepter.............方法后......" + str);

        return result;
    }
}
